import request from '@/utils/request'
import { get, post } from "@/utils/request"
import { axios } from '@/utils/request'

  
 //post请求
export function postAction(url,parameter) {
    return axios({
      url: url,
      method:'post' ,
      data: parameter
    })
}

//get
export function getAction(url,parameter) {
    return axios({
      url: url,
      method: 'get',
      params: parameter
    })
  }

//put
export function putAction(url,parameter) {
    return axios({
      url: url,
      method:'put',
      data: parameter
    })
}

//deleteAction
export function deleteAction(url,parameter) {
  return axios({
    url: url,
    method: 'delete',
    data: parameter,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}


//formdata请求提交
  export function postForm(url,parameter){
    return axios({
      url: url,
      data: parameter,
      method:'post' ,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded', 
      },
    })
  }



const api = {
  user: '/user',
  role: '/role',
  service: '/service',
  permission: '/permission',
  permissionNoPager: '/permission/no-pager',
  orgTree: '/org/tree'
}

export default api



// id == 0 add     post
// id != 0 update  put
export function saveService (parameter) {
  return request({
    url: api.service,
    method: parameter.id === 0 ? 'post' : 'put',
    data: parameter
  })
}

export function saveSub (sub) {
  return request({
    url: '/sub',
    method: sub.id === 0 ? 'post' : 'put',
    data: sub
  })
}
